import { ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { I18nMessageId, ObjectType } from 'typings/interfaces'
import { OperateTypes } from '@/enums/operateTypes'

/**
 * 表单 hooks
 */
function useExpandForm() {
  const { t } = useI18n()
  const expandVisible = ref<boolean>(false)
  const expandTitle = ref<string>('')
  const expandInitialValues = ref<ObjectType>({})
  const expandOperateType = ref<OperateTypes | null>(null)
  const expandParams = ref<ObjectType>({})
  const expandAction = (type: OperateTypes, titleId: I18nMessageId, initValues: ObjectType) => {
    expandOperateType.value = type
    expandTitle.value = t(titleId)
    expandInitialValues.value = initValues
    expandVisible.value = true
    expandParams.value = initValues
  }

  return {
    expandAction,
    expandVisible,
    expandTitle,
    expandInitialValues,
    expandOperateType,
    expandParams,
  }
}

export default useExpandForm
